package com.com.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;
import java.sql.DriverManager;
import java.util.List;
import java.util.Map;


@RestController
public class jdbcController {

    //自动配置 jdbcTemplate，获取对象
    JdbcTemplate jdbcTemplate;  //xxxTemplate
    @Autowired
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @RequestMapping("/a")
    //数据库的数据都是键值对 储存的，想要获取全部通一个集合包涵多个键值对
    public List<Map<String, Object>> name(){

        String sql="select * from mybaitis.user";
        List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql);

        return maps;
    }

    @GetMapping("/b")
    public String del(){
        String sql="delete from user where id=6";
        jdbcTemplate.execute(sql);
        return "ok";
    }
    @GetMapping("c")
    public String ins(){

        String sql= "insert into user(id,password,name,age) values(6,'222','小可爱哦',3)";
        jdbcTemplate.execute(sql);
        return "ofCou";



    }


}
